package simplyrugby.controller;


import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import simplyrugby.common.Result;
import simplyrugby.entity.Position;
import simplyrugby.service.PositionService;

import java.util.List;

@RestController
@RequestMapping("/api/position")
@RequiredArgsConstructor
public class PositionController {
    private final PositionService positionService;


    @PostMapping
    public Result add(@RequestBody Position position) {
        boolean save = positionService.save(position);
        return Result.success().data(save);
    }

    @DeleteMapping("/{id}")
    public Result removeById(@PathVariable String id) {
        boolean b = positionService.removeById(id);
        return Result.success().data(b);
    }

    @PutMapping
    public Result updateById(@RequestBody Position position) {
        boolean flag = positionService.updateById(position);
        return flag ? Result.success() : Result.fail();
    }


    @GetMapping("/{id}")
    public Result details(@PathVariable String id) {
        Position position = positionService.getById(id);
        return Result.success().data(position);
    }

    @GetMapping("/list")
    public Result list() {
        List<Position> list = positionService.list();
        return Result.success().data(list);
    }
}

